package c.d.a.a.j;

/* compiled from: ObjectPool */
public class e<T extends a> {
    public static int g;
    public int a;
    public int b;
    public Object[] c;
    public int d;
    public T e;
    public float f;

    /* compiled from: ObjectPool */
    public static abstract class a {
        public int a = -1;

        public abstract a a();
    }

    public e(int i, T t) {
        if (i > 0) {
            this.b = i;
            this.c = new Object[i];
            this.d = 0;
            this.e = t;
            this.f = 1.0f;
            d();
            return;
        }
        throw new IllegalArgumentException("Object Pool must be instantiated with a capacity greater than 0!");
    }

    public static synchronized e a(int i, a aVar) {
        e eVar;
        synchronized (e.class) {
            eVar = new e(i, aVar);
            i = g;
            eVar.a = i;
            g = i + 1;
        }
        return eVar;
    }

    public synchronized T b() {
        a aVar;
        if (this.d == -1 && this.f > 0.0f) {
            d();
        }
        Object[] objArr = this.c;
        int i = this.d;
        aVar = (a) objArr[i];
        aVar.a = -1;
        this.d = i - 1;
        return aVar;
    }

    public synchronized void c(T t) {
        int i = t.a;
        if (i == -1) {
            i = this.d + 1;
            this.d = i;
            if (i >= this.c.length) {
                i = this.b;
                int i2 = i * 2;
                this.b = i2;
                Object[] objArr = new Object[i2];
                for (int i3 = 0; i3 < i; i3++) {
                    objArr[i3] = this.c[i3];
                }
                this.c = objArr;
            }
            t.a = this.a;
            this.c[this.d] = t;
        } else if (i == this.a) {
            throw new IllegalArgumentException("The object passed is already stored in this pool!");
        } else {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("The object to recycle already belongs to poolId ");
            stringBuilder.append(t.a);
            stringBuilder.append(".  Object cannot belong to two different pool instances simultaneously!");
            throw new IllegalArgumentException(stringBuilder.toString());
        }
    }

    public final void d() {
        float f = this.f;
        int i = this.b;
        int i2 = (int) (((float) i) * f);
        if (i2 < 1) {
            i = 1;
        } else if (i2 <= i) {
            i = i2;
        }
        for (i2 = 0; i2 < i; i2++) {
            this.c[i2] = this.e.a();
        }
        this.d = i - 1;
    }

    public void e(float f) {
        if (f > 1.0f) {
            f = 1.0f;
        } else if (f < 0.0f) {
            f = 0.0f;
        }
        this.f = f;
    }
}
